package cn.lhl.sys.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author lhl
 * @since 2023-02-08
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_user")
public class SysUser  implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 名
     */
    @TableField("username")
    private String username;

    /**
     * 密码
     */
    @TableField("password")
    private String password;


    /*角色的*/
    @TableField(exist = false)
    private List<SysRole> sysRoleList = new ArrayList<>();
    /*资源的*/
    @TableField(exist = false)
    private List<SysMenu> sysMenuList = new ArrayList<>();



    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    /* 获取当前用户对应的 资源 权限列表 */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return sysMenuList;
    }
}
